package com.tust.app.service.impl;

import com.tust.app.dao.NewsMapper;
import com.tust.app.domain.News;
import com.tust.app.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    private NewsMapper newsMapper;

    @Override
    public List<News> newsList()  throws Exception{
        return newsMapper.selectAllNews();
    }
    public List<News> serach(String title) throws Exception {
        if(title!=null && title.length()>0) {
            return newsMapper.selectNewsByTitle(title);
        }else {
            return newsMapper.selectAllNews();
        }
    }

    @Override
    public Integer addArticle(News news)  throws Exception{

        return newsMapper.writeNews(news);
    }

    @Override
    public News findNewsById(Integer id)  throws Exception{
        return newsMapper.selectNewsById(id);
    }

    @Override
    public boolean delNews(Integer id)  throws Exception{
        return newsMapper.deleteNewsById(id);
    }

    @Override
    public boolean modifyNews(News news)  throws Exception{
        return newsMapper.updateNewsById(news);
    }

}
